package com.erps.sys.rest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.erps.CommonUtils.StringEx;
import com.erps.db.DBManager;
import com.hmkj.entity.vo.ErspCodeValueVO;

public class ErspCodeValueRest {

	public List<ErspCodeValueVO> Find(int cTypeID) {
		StringBuffer sql = new StringBuffer();
		sql.append(" select * ");
		sql.append(" from ersp_code_value ");
		sql.append(" where code_type='" + cTypeID + "'");
		List<ErspCodeValueVO> vret = new ArrayList<ErspCodeValueVO>();

		List<Map<String, String>> rs = DBManager.QueryData(sql.toString());
		int iLength = (rs == null) ? 0 : rs.size();
		for (int i = 0; i < iLength; i++) {
			ErspCodeValueVO vo = new ErspCodeValueVO();
			vo.setId(StringEx.getMapVal(rs.get(i), "id"));
			vo.setCode_name_id(StringEx.getMapVal(rs.get(i), "code_name_id"));
			vo.setCode_type(StringEx.getMapVal(rs.get(i), "code_type"));
			vo.setCode_value(StringEx.getMapVal(rs.get(i), "code_value"));
			vret.add(vo);
		}

		return vret;
	}

	public ErspCodeValueVO FindItem(int iTypeID) {
		StringBuffer sql = new StringBuffer();
		sql.append(" select * ");
		sql.append(" from ersp_code_value ");
		sql.append(" where code_name_id='" + String.valueOf(iTypeID) + "'");
		Map<String, String> rs = DBManager.GetRow(sql.toString());
		if (rs != null) {
			ErspCodeValueVO vo = new ErspCodeValueVO();
			vo.setId(StringEx.getMapVal(rs, "id"));
			vo.setCode_name_id(StringEx.getMapVal(rs, "code_name_id"));
			vo.setCode_type(StringEx.getMapVal(rs, "code_type"));
			vo.setCode_value(StringEx.getMapVal(rs, "code_value"));
			return vo;
		} else {
			return null;
		}
	}
}